<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>键鼠监听面板</title>
  <style>
    body {
      width: 100%;
      min-height: 100vh;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      margin: 0;
      padding: 16px;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: #333;
      box-sizing: border-box;
      overflow-x: hidden;
    }
    
    .header {
      background: rgba(255, 255, 255, 0.95);
      padding: 12px 16px;
      border-radius: 10px;
      margin-bottom: 16px;
      box-shadow: 0 4px 15px rgba(0,0,0,0.1);
      overflow: hidden;
    }
    
    .header h1 {
      margin: 0;
      color: #2c3e50;
      font-size: 24px;
      display: flex;
      align-items: center;
      gap: 10px;
    }
    
    .status {
      margin-top: 10px;
      padding: 8px 12px;
      background: #e8f5e8;
      border-left: 4px solid #27ae60;
      border-radius: 4px;
      font-size: 14px;
    }
    
    .controls {
      background: rgba(255, 255, 255, 0.95);
      padding: 12px 16px;
      border-radius: 10px;
      margin-bottom: 16px;
      box-shadow: 0 4px 15px rgba(0,0,0,0.1);
      overflow: hidden;
    }
    
    .btn {
      background: #3498db;
      color: white;
      border: none;
      padding: 10px 20px;
      border-radius: 6px;
      cursor: pointer;
      margin-right: 10px;
      font-size: 14px;
      transition: background 0.3s;
    }
    
    .btn:hover {
      background: #2980b9;
    }
    
    .btn.primary {
      background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
      font-weight: 600;
    }
    
    .btn.primary:hover {
      background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
      transform: translateY(-2px);
      box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
    }
    
    .btn.primary.active {
      background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
      box-shadow: 0 0 15px rgba(40, 167, 69, 0.5);
      animation: pulse 2s infinite;
    }
    
    @keyframes pulse {
      0% { box-shadow: 0 0 15px rgba(40, 167, 69, 0.5); }
      50% { box-shadow: 0 0 25px rgba(40, 167, 69, 0.8); }
      100% { box-shadow: 0 0 15px rgba(40, 167, 69, 0.5); }
    }
    
    .btn.danger {
      background: #e74c3c;
    }
    
    .btn.danger:hover {
      background: #c0392b;
    }
    
    .events-container {
      background: rgba(255, 255, 255, 0.95);
      border-radius: 10px;
      padding: 16px;
      box-shadow: 0 4px 15px rgba(0,0,0,0.1);
      max-height: calc(100vh - 280px);
      overflow-y: auto;
      overflow-x: hidden;
    }
    
    .event {
      background: white;
      border-left: 5px solid #3498db;
      padding: 15px 20px;
      margin-bottom: 15px;
      border-radius: 8px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
      transition: transform 0.2s, box-shadow 0.2s;
    }
    
    .event:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    }
    
    .event.click {
      border-left-color: #e74c3c;
    }
    
    .event.key {
      border-left-color: #f39c12;
    }
    
    .event.selector-captured {
      border-left-color: #28a745;
    }
    
    .event.workflow-action {
      border-left-color: #ff6b35;
    }
    
    /* 模式切换标签 */
    .mode-tabs {
      display: flex;
      margin-top: 15px;
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .tab-btn {
      flex: 1;
      padding: 12px 16px;
      border: none;
      background: #e9ecef;
      color: #495057;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s ease;
    }
    
    .tab-btn:hover {
      background: #dee2e6;
    }
    
    .tab-btn.active {
      background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
      color: white;
    }
    
    /* 隐藏元素 */
    .hidden {
      display: none !important;
    }
    
    /* 录制按钮样式 */
    .btn.recording {
      background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
      font-weight: 600;
    }
    
    .btn.recording:hover {
      background: linear-gradient(135deg, #c82333 0%, #a71e2a 100%);
      transform: translateY(-2px);
      box-shadow: 0 4px 15px rgba(220, 53, 69, 0.4);
    }
    
    .btn.recording.active {
      background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
      box-shadow: 0 0 15px rgba(255, 107, 53, 0.5);
      animation: recording-pulse 2s infinite;
    }
    
    @keyframes recording-pulse {
      0% { box-shadow: 0 0 15px rgba(255, 107, 53, 0.5); }
      50% { box-shadow: 0 0 25px rgba(255, 107, 53, 0.8); }
      100% { box-shadow: 0 0 15px rgba(255, 107, 53, 0.5); }
    }
    
    /* 工作流统计 */
    .workflow-stats {
      background: rgba(255, 255, 255, 0.95);
      padding: 12px;
      border-radius: 8px;
      margin-bottom: 20px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
      overflow: hidden;
    }
    
    .stat-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 4px 0;
      border-bottom: 1px solid #eee;
      min-height: 24px;
    }
    
    .stat-item:last-child {
      border-bottom: none;
    }
    
    .stat-label {
      font-weight: 600;
      color: #495057;
      font-size: 12px;
      flex-shrink: 0;
      margin-right: 8px;
    }
    
    .stat-item span:last-child {
      color: #007bff;
      font-weight: 600;
      font-size: 12px;
      text-align: right;
      word-break: break-all;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 50%;
    }
    
    .event-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 10px;
    }
    
    .event-type {
      font-weight: bold;
      font-size: 16px;
      color: #2c3e50;
    }
    
    .event-time {
      color: #7f8c8d;
      font-size: 12px;
      background: #ecf0f1;
      padding: 4px 8px;
      border-radius: 12px;
    }
    
    .event-details {
      background: #f8f9fa;
      padding: 12px;
      border-radius: 6px;
      font-family: 'Courier New', monospace;
      font-size: 13px;
      line-height: 1.5;
      white-space: pre-wrap;
      border: 1px solid #e9ecef;
    }
    
    .empty-state {
      text-align: center;
      color: #7f8c8d;
      padding: 60px 20px;
      font-size: 16px;
    }
    
    .empty-state .icon {
      font-size: 48px;
      margin-bottom: 20px;
      opacity: 0.5;
    }
    
    .stats {
      display: flex;
      gap: 15px;
      margin-top: 15px;
    }
    
        .stat {
      background: #ecf0f1;
      padding: 8px 12px;
      border-radius: 6px;
      font-size: 12px;
    }

    /* 字段配置样式 */
    .field-config {
      max-height: 300px;
      overflow-y: auto;
    }

    .field-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 0;
      border-bottom: 1px solid #eee;
    }

    .field-item:last-child {
      border-bottom: none;
    }

    .field-checkbox {
      width: 16px;
      height: 16px;
    }

    .field-name {
      flex: 1;
      font-size: 12px;
      padding: 4px 8px;
      border: 1px solid #ddd;
      border-radius: 3px;
      background: white;
    }

    .field-selector {
      flex: 2;
      font-size: 11px;
      color: #666;
      background: #f8f9fa;
      padding: 4px 6px;
      border-radius: 3px;
      font-family: monospace;
    }

    .field-type {
      font-size: 10px;
      padding: 2px 6px;
      border-radius: 3px;
      background: #e9ecef;
      color: #495057;
    }

    /* 数据表格样式 */
    .data-table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 10px;
      font-size: 11px;
    }

    .data-table th {
      background: #f8f9fa;
      border: 1px solid #dee2e6;
      padding: 6px 8px;
      text-align: left;
      font-weight: 600;
      color: #495057;
    }

    .data-table td {
      border: 1px solid #dee2e6;
      padding: 6px 8px;
      max-width: 150px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .data-table tr:nth-child(even) {
      background: #f8f9fa;
    }

    .data-table tr:hover {
      background: #e3f2fd;
    }

    /* 抓取状态样式 */
    .extraction-status {
      background: rgba(255, 255, 255, 0.95);
      padding: 10px;
      border-radius: 6px;
      margin-bottom: 10px;
      border-left: 4px solid #007bff;
      font-size: 12px;
    }

    .extraction-progress {
      width: 100%;
      height: 6px;
      background: #e9ecef;
      border-radius: 3px;
      overflow: hidden;
      margin-top: 5px;
    }

    .extraction-progress-bar {
      height: 100%;
      background: linear-gradient(90deg, #007bff, #0056b3);
      transition: width 0.3s ease;
    }

    ::-webkit-scrollbar {
      width: 8px;
    }
    
    ::-webkit-scrollbar-track {
      background: #f1f1f1;
      border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb {
      background: #c1c1c1;
      border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
      background: #a1a1a1;
    }
  </style>
</head>
<body>
  <div class="header">
    <h1>🎯 智能自动化工具</h1>
    <div class="status" id="status">
      选择模式：捕获元素选择器 | 录制模式：记录操作序列生成工作流
    </div>
    
                <!-- 模式切换标签 -->
            <div class="mode-tabs">
              <button class="tab-btn active" id="selectorTab">🎯 选择器</button>
              <button class="tab-btn" id="workflowTab">📝 工作流</button>
              <button class="tab-btn" id="dataTab">📊 数据抓取</button>
            </div>
  </div>
  
  <!-- 选择器模式控制 -->
  <div class="controls" id="selectorControls">
    <button class="btn primary" id="hoverModeBtn">🎯 开始选择</button>
    <button class="btn danger" id="clearBtn">🗑️ 清空记录</button>
    <button class="btn" id="exportBtn">📤 导出选择器</button>
  </div>
  
            <!-- 工作流模式控制 -->
          <div class="controls hidden" id="workflowControls">
            <button class="btn recording" id="recordModeBtn">🔴 开始录制</button>
            <button class="btn danger" id="clearWorkflowBtn">🗑️ 清空工作流</button>
            <button class="btn" id="exportWorkflowBtn">📤 导出工作流</button>
          </div>

          <!-- 数据抓取模式控制 -->
          <div class="controls hidden" id="dataControls">
            <button class="btn primary" id="selectTableBtn">🎯 选择表格</button>
            <button class="btn" id="configFieldsBtn">⚙️ 配置字段</button>
            <button class="btn" id="extractDataBtn">📊 开始抓取</button>
            <button class="btn danger" id="clearDataBtn">🗑️ 清空数据</button>
            <button class="btn" id="exportDataBtn">📤 导出数据</button>
          </div>
  
            <!-- 工作流统计信息 -->
          <div class="workflow-stats hidden" id="workflowStats">
            <div class="stat-item">
              <span class="stat-label">时间:</span>
              <span id="recordingDuration">00:00</span>
            </div>
            <div class="stat-item">
              <span class="stat-label">动作:</span>
              <span id="actionCount">0</span>
            </div>
            <div class="stat-item">
              <span class="stat-label">页面:</span>
              <span id="currentUrl" title="">-</span>
            </div>
          </div>

          <!-- 数据抓取统计信息 -->
          <div class="workflow-stats hidden" id="dataStats">
            <div class="stat-item">
              <span class="stat-label">表格:</span>
              <span id="tableSelector">未选择</span>
            </div>
            <div class="stat-item">
              <span class="stat-label">行数:</span>
              <span id="rowCount">0</span>
            </div>
            <div class="stat-item">
              <span class="stat-label">字段:</span>
              <span id="fieldCount">0</span>
            </div>
          </div>

          <!-- 字段配置面板 -->
          <div class="field-config hidden" id="fieldConfig">
            <div style="background: rgba(255, 255, 255, 0.95); padding: 12px; border-radius: 8px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
              <h4 style="margin: 0 0 10px 0; color: #2c3e50; font-size: 14px;">📋 字段配置</h4>
              <div id="fieldList"></div>
              <div style="margin-top: 10px;">
                <button class="btn" id="addFieldBtn" style="font-size: 12px; padding: 6px 12px;">➕ 添加字段</button>
                <button class="btn primary" id="confirmFieldsBtn" style="font-size: 12px; padding: 6px 12px;">✅ 确认配置</button>
              </div>
            </div>
          </div>
  
  <div class="events-container">
    <div id="events">
      <div class="empty-state">
        <div class="icon">🎯</div>
        <div>点击"开始选择"，然后在页面上点击元素来捕获选择器</div>
      </div>
    </div>
  </div>

  <script src="sidepanel.js"></script>
</body>
</html> 